package com.leo;

import com.almasb.fxgl.app.GameApplication;
import com.almasb.fxgl.app.GameSettings;
import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.Entity;
import com.leo.entity.ScrollEntityFactory;
import javafx.scene.input.KeyCode;

/**
 * @Author: wangss
 * @CreateTime: 2023-06-19  22:42
 * @Description: 无缝地图
 */
public class ScrollApp extends GameApplication {

    private Entity player;

    @Override
    protected void initSettings(GameSettings settings) {
        settings.setWidth(512);
        settings.setHeight(294);
    }

    @Override
    protected void initInput() {
        FXGL.onKey(KeyCode.RIGHT, () -> {
            player.translateX(10);
        });
        FXGL.onKey(KeyCode.LEFT, () -> {
            player.translateX(-10);
        });
    }

    @Override
    protected void initGame() {
        FXGL.getGameWorld().addEntityFactory(new ScrollEntityFactory());
        FXGL.spawn("bg");
        player = FXGL.spawn("player", 0, FXGL.getAppHeight() / 2);
        FXGL.getGameScene().getViewport().bindToEntity(player, FXGL.getAppWidth() / 2, FXGL.getAppHeight() / 2);
//        FXGL.getGameScene().getViewport().setLazy(true);
        FXGL.getGameScene().getViewport().setFloating(true);
    }

    public static void main(String[] args) {
        launch(args);
    }
}
